package com.ucode.hrm.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ucode.hrm.mapper.HrmEmployeeMapper;
import com.ucode.model.hrm.HrmEmployee;
import com.ucode.model.hrm.enums.HrmSysResultCodeEnum;
import com.ucode.springboot.starter.mybatis.core.base.BaseService;
import com.ucode.tool.base.enums.GlobalResultCodeEnum;
import com.ucode.tool.exception.UcodeServiceException;
import com.ucode.tool.util.CollectionUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工表 Service 接口
 * @Author: liliang
 * @Date: 2025/6/1 14:49
 * @Version: 1.0
 */
public interface HrmEmployeeService extends BaseService<Long, HrmEmployee, HrmEmployeeMapper> {

    /**
     * 查询会员绑定员工信息
     * @param memberId
     * @return
     */
    public HrmEmployee selectBindStatusInfo(Long memberId);
    /**
     * 根据姓名和身份证号查询员工状态信息
     * @param realName
     * @param idCardNumber
     * @return
     */
    public HrmEmployee selectStatusByIdentity(String realName,  String idCardNumber);

    /**
     * 绑定员工
     * @param employeeId
     * @param memberId
     * @return
     */
    public int bind(Long employeeId, Long memberId);

    /**
     * 更新员工社保处理标识
     * @param ids
     * @param sspMark
     * @return
     */
    public int updateSspMark(Collection<Long> ids, Boolean sspMark);
    /**
     * 根据身份证号查询员工
     * @param idCardNumber
     * @return
     */
    default HrmEmployee getByIdCardNumber(String idCardNumber) {
        if(ObjectUtil.isNull(idCardNumber))
            throw new UcodeServiceException(GlobalResultCodeEnum.VALIDATE_FAILED);

        Map<String, Object> params = new HashMap<>();
        params.put("idCardNumber", idCardNumber);
        params.put("deltag", false);
        List<HrmEmployee> list = this.queryObjectForList(params,0);
        return CollUtil.isNotEmpty(list) ? list.get(0) : null;
    }

    default Map<Long, HrmEmployee> getMap(Collection<Long> ids) {
        return CollUtil.isEmpty(ids) ? new HashMap() : CollectionUtils.convertMap(this.selectBaseInfoByPrimaryKeys(ids), HrmEmployee::getId);
    }

    /**
     * 验证是否合法并返回
     * @param id
     * @return
     */
    default HrmEmployee validate(Long id){
        if(ObjectUtil.isNull(id) )
            throw new UcodeServiceException(GlobalResultCodeEnum.VALIDATE_FAILED);
        //验证数据是否存在
        HrmEmployee brand = this.selectByPrimaryKey(id);
        if(ObjectUtil.isNull(brand) || brand.getDeltag()){
            throw new UcodeServiceException(HrmSysResultCodeEnum.EMPLOYEE_NOT_EXISTS);
        }
        return brand;
    }

}
